package cn.zh.stan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import cn.zh.stan.ITem.HgItem;
import cn.zh.stan.R;

/**
 * Created by WYN on 2018/1/15 0015.
 */

public class HGadapter extends BaseAdapter{
 public Context context;
 ArrayList<HgItem> arrayList;
 LayoutInflater inflater;

 public HGadapter(Context context,ArrayList<HgItem> arrayList){
     this.context=context;
     this.arrayList=arrayList;
     inflater=LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return arrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
       }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder=null;
        if (null==view){
            holder=new Holder();
            view= inflater.inflate(R.layout.hg_layout,null,false);
            holder.hfimag=view.findViewById(R.id.hfimag);
            holder.htcar=view.findViewById(R.id.htcar);
            holder.hftxt=view.findViewById(R.id.hftxt);
            holder.htprice=view.findViewById(R.id.htprice);
            holder.hgunit=view.findViewById(R.id.hgunit);
            view.setTag(holder);
        }else {
            holder= (Holder) view.getTag();
         }
        holder.hftxt.setText(arrayList.get(i).getGoodsName());
        holder.htprice.setText(arrayList.get(i).getPrice_Detail());
        holder.hgunit.setText("/"+arrayList.get(i).getUnit());
        return view;
    }


    public class Holder{
        ImageView hfimag,htcar;
        TextView hftxt,htprice,hgunit;
    }

}
